#include <QSettings>
#include <QVariant>
#include <QCheckBox>

#include "optionsdialog.h"
#include "ui_optionsdialog.h"

OptionsDialog::OptionsDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::OptionsDialog)
{
    ui->setupUi(this);

    connect(ui->okPushButton, SIGNAL(clicked()), this, SLOT(saveSettingsAndClose()));

    loadSettings();

    //QSettings settings("f", "g");
    //ui->splashCheckBox->setObjectName("splashOption");
    //ui->splashCheckBox=settings.value("setChecked", ui->splashCheckBox->isChecked());

    //settings.setValue("setChecked",  ui->splashCheckBox);
}

void OptionsDialog::saveSettings()
{
    QSettings settings("Trolltech", "Application Example");
    settings.setValue("myCheckBox", ui->splashCheckBox->isChecked());

    //ui->splashCheckBox->setChecked(settings.value("myCheckBox", false /* default value */).toBool());


    //ui->splashCheckBox = settings.setValue("splashOption", ui->splashCheckBox->isChecked());
    //ui->splashCheckBox->setChecked(settings.setValue("splashOption", false).toBool());
       //settings.setValue("text", sText);
       //if (m_pLabel)
       //{
       //    m_pLabel->setText(sText);
       //}

}

void OptionsDialog::loadSettings()
{
    QSettings settings("Trolltech", "Application Example");

    ui->splashCheckBox->setChecked(settings.value("myCheckBox", false /* default value */).toBool());
    //ui->splashCheckBox = settings.value("myCheckBox", "").value<QCheckBox>;
    //if (m_pLabel) {
    //    m_pLabel->setText(sText);
    //}
}

void OptionsDialog::closeEvent(QCloseEvent *event)
{
    //if (ui->okPushButton->) {
        //saveSettings();
       // event->accept();
    //} else {
    //    event->ignore();
    //}
}

void OptionsDialog::saveSettingsAndClose() {
    saveSettings();
    this->close();

}

OptionsDialog::~OptionsDialog()
{
    //saveSettings();
    delete ui;
}
